**************************
**** CHANGE DIRECTORY ****
**************************

cd "XXX" 

**************************
**** FIGURE 2a ***********
**************************
use "data.dta", clear
set more off

*distributions of leadership aspirations by gender
twoway (histogram leadasp if female==1, discrete xscale(range(1(1)10)) yscale(range(0(5)30)) ylabel(0(5)30, labsize(medlarge)) color(gs12) percent) ///
(histogram leadasp if female==0, discrete xscale(range(1 10)) ylabel(0(5)30) fcolor(none) lcolor(black) percent), ///
legend(row(1) order(1 "Women" 2 "Men") size(large) symxsize(10) keygap(0.8) position(6)) ///
scheme(lean1) ///
xlabel(1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6" 7 "7" 8 "8" 9 "9" 10 "10", noticks labsize(medlarge)) ///
xtitle("Willingness to lead", size(5)) ytitle("Percent", size(5)) ysize(7) xsize(10) ///
graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white))

graph export "figure2a.pdf", replace
graph export "figure2a.tif", replace

**************************
**** FIGURE 2b ***********
**************************
use "data.dta", clear
set more off

preserve

gen ci_lb=.
gen ci_ub=.
gen se_lb=.
gen se_ub=.

*Women in male dominated teams 
ci means leadasp if female==1 & group_female==0
replace ci_lb=r(lb) if female==1 & group_female==0
replace ci_ub=r(ub) if female==1 & group_female==0
replace se_lb=r(mean)-r(se) if female==1 & group_female==0
replace se_ub=r(mean)+r(se) if female==1 & group_female==0

*Women in female dominated teams 
ci means leadasp if female==1 & group_female==1
replace ci_lb=r(lb) if female==1 & group_female==1
replace ci_ub=r(ub) if female==1 & group_female==1
replace se_lb=r(mean)-r(se) if female==1 & group_female==1
replace se_ub=r(mean)+r(se) if female==1 & group_female==1

*Men in male dominated teams 
ci means leadasp if female==0 & group_female==0
replace ci_lb=r(lb) if female==0 & group_female==0
replace ci_ub=r(ub) if female==0 & group_female==0
replace se_lb=r(mean)-r(se) if female==0 & group_female==0
replace se_ub=r(mean)+r(se) if female==0 & group_female==0

*Men in female dominated teams 
ci means leadasp if female==0 & group_female==1
replace ci_lb=r(lb) if female==0 & group_female==1
replace ci_ub=r(ub) if female==0 & group_female==1
replace se_lb=r(mean)-r(se) if female==0 & group_female==1
replace se_ub=r(mean)+r(se) if female==0 & group_female==1

sort female group_female

collapse (mean) leadasp ci_lb ci_ub se_lb se_ub, by(female group_female)

*Help Variables
generate x_axis=0.1 if female==1 & group_female==1
replace x_axis=0.3 if female==1 & group_female==0

replace x_axis=0.7 if female==0 & group_female==1
replace x_axis=0.9 if female==0 & group_female==0

sort x_axis
label var x_axis " "

*Bar Chart
twoway (bar leadasp x_axis if female==1 & group_female==1, barw(0.15) bcolor(gs10)) ///
(bar leadasp x_axis if female==1 & group_female==0, barw(0.15) bcolor(gs1)) ///
(bar leadasp x_axis if female==0 & group_female==1, barw(0.15) bcolor(gs10)) ///
(bar leadasp x_axis if female==0 & group_female==0, barw(0.15) bcolor(gs1)) ///
(rcap se_ub se_lb x_axis, lcolor(gs1.5)), ///
legend(row(1) order(1 "Female-majority team" 2 "Male-majority team") size(medlarge) symxsize(10) keygap(0.8) position(6)) ///
xscale(range(0 1)) ///
xlabel(0.2 "Women" 0.8 "Men", noticks labsize(large)) ///
ytitle("Willingness to lead", size(5)) ///
ylabel(3(1)9, labsize(medlarge)) ///
graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white))
graph export "figure2b.pdf", replace
graph export "figure2b.tif", replace

restore

**************************
**** FIGURE 2c ***********
**************************
use "data.dta", clear
set more off

preserve

gen ci_lb=.
gen ci_ub=.

gen se_lb=.
gen se_ub=.

foreach y in 1 2 3 4 {

*Women in male dominated teams
ci means leadasp if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==1 & group_female==0 & rank_perf_1_reversed==`y'

*Women in female dominated teams 
ci means leadasp if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==1 & group_female==1 & rank_perf_1_reversed==`y'

*Men in male dominated teams 
ci means leadasp if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==0 & group_female==0 & rank_perf_1_reversed==`y'

*Men in female dominated teams 
ci means leadasp if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
}

sort female group_female

collapse (mean) leadasp ci_lb ci_ub se_lb se_ub, by(female rank_perf_1_reversed group_female)

sort rank_perf_1_reversed

*Graph (all)
twoway (scatter leadasp rank_perf_1_reversed if female==0 & group_female==1, connect(l) lcolor(gray) mcolor(gray) lpattern(dash) msymbol(d)) ///
(scatter leadasp rank_perf_1_reversed if female==0 & group_female==0, connect(l) lcolor(black) mcolor(black) lpattern(dash) msymbol(d)) ///
(scatter leadasp rank_perf_1_reversed if female==1 & group_female==1, connect(l) lcolor(gray) mcolor(gray)) ///
(scatter leadasp rank_perf_1_reversed if female==1 & group_female==0, connect(l) lcolor(black) mcolor(black)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==0 & group_female==1, lcolor(gray)) /// 
(rcap se_ub se_lb rank_perf_1_reversed if female==0 & group_female==0, lcolor(black)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==1 & group_female==1, lcolor(gray)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==1 & group_female==0, lcolor(black)), ///
legend(row(4) stack keygap(0.7) rowgap(5) symxsize(30) bmargin(left) order(1 "Men in female-majority teams" 2 "Men in male-majority teams" 3 "Women in female-majority teams" 4 "Women in male-majority teams") size(medlerge) position(3)) ///
xscale(range(1 4)) xsize(13) ysize(7) ///
xlabel(1 "4th" 2 "3rd" 3 "2nd" 4 "1st", noticks labsize(large)) ///
xtitle("Relative performance on first task", size(5)) ///
ytitle("Willingness to lead", size(5)) ///
ylabel(3(1)9, labsize(large)) ///
graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white))
graph export "figure2c.pdf", replace
graph export "figure2c.tif", replace

restore

**************************
**** FIGURE 3 ************
**************************

use "data.dta", clear
set more off

******3a: guess of relative performance

preserve

gen ci_lb=.
gen ci_ub=.

gen se_lb=.
gen se_ub=.

foreach y in 1 2 3 4 {

*Women in male dominated teams
ci means guess_rank_1_reversed if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==1 & group_female==0 & rank_perf_1_reversed==`y'

*Women in female dominated teams 
ci means guess_rank_1_reversed if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==1 & group_female==1 & rank_perf_1_reversed==`y'

*Men in male dominated teams 
ci means guess_rank_1_reversed if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==0 & group_female==0 & rank_perf_1_reversed==`y'

*Men in female dominated teams 
ci means guess_rank_1_reversed if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
}

sort female group_female

collapse (mean) guess_rank_1_reversed ci_lb ci_ub se_lb se_ub, by(female rank_perf_1_reversed group_female)

sort rank_perf_1
gen one=1
gen four=4

*Graph (all)
twoway (rarea four rank_perf_1_reversed rank_perf_1_reversed, color(gs14)) ///
(line rank_perf_1_reversed rank_perf_1_reversed, lcolor(black) lpattern(shortdash)) ///
(scatter guess_rank_1_reversed rank_perf_1_reversed if female==0 & group_female==1, connect(l) lcolor(gray) mcolor(gray) lpattern(dash) msymbol(d)) ///
(scatter guess_rank_1_reversed rank_perf_1_reversed if female==0 & group_female==0, connect(l) lcolor(black) mcolor(black) lpattern(dash) msymbol (d)) ///
(scatter guess_rank_1_reversed rank_perf_1_reversed if female==1 & group_female==1, connect(l) lcolor(gray) mcolor(gray)) ///
(scatter guess_rank_1_reversed rank_perf_1_reversed if female==1 & group_female==0, connect(l) lcolor(black) mcolor(black)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==0 & group_female==1, lcolor(gray)) /// 
(rcap se_ub se_lb rank_perf_1_reversed if female==0 & group_female==0, lcolor(black)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==1 & group_female==1, lcolor(gray)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==1 & group_female==0, lcolor(black)), ///
legend(off) ///
xscale(range(1 4)) xsize(9) ysize(7) ///
xlabel(1 "4th" 2 "3rd" 3 "2nd" 4 "1st", noticks labsize(large)) ///
xtitle("Relative performance on first task", size(6)) ///
ytitle("Guess of relative performance", size(6)) ///
ylabel(1 "4th" 2 "3rd" 3 "2nd" 4 "1st", labsize(large)) ///
graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white))
graph export "figure3a.pdf", replace
graph export "figure3a.tif", replace

restore

******3b: updating

preserve

gen ci_lb=.
gen ci_ub=.

gen se_lb=.
gen se_ub=.

foreach y in 1 2 3 4 {

*Women in male dominated teams
ci means relative_updating if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==1 & group_female==0 & rank_perf_1_reversed==`y'

*Women in female dominated teams 
ci means relative_updating if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==1 & group_female==1 & rank_perf_1_reversed==`y'

*Men in male dominated teams 
ci means relative_updating if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==0 & group_female==0 & rank_perf_1_reversed==`y'

*Men in female dominated teams 
ci means relative_updating if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
}

sort female group_female

collapse (mean) relative_updating ci_lb ci_ub se_lb se_ub, by(female rank_perf_1_reversed group_female)

sort rank_perf_1_reversed

*Graph (all)
twoway (scatter relative_updating rank_perf_1_reversed if female==0 & group_female==1, connect(l) lcolor(gray) mcolor(gray) lpattern(dash) msymbol(d)) ///
(scatter relative_updating rank_perf_1_reversed if female==0 & group_female==0, connect(l) lcolor(black) mcolor(black) lpattern(dash) msymbol(d)) ///
(scatter relative_updating rank_perf_1_reversed if female==1 & group_female==1, connect(l) lcolor(gray) mcolor(gray)) ///
(scatter relative_updating rank_perf_1_reversed if female==1 & group_female==0, connect(l) lcolor(black) mcolor(black)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==0 & group_female==1, lcolor(gray)) /// 
(rcap se_ub se_lb rank_perf_1_reversed if female==0 & group_female==0, lcolor(black)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==1 & group_female==1, lcolor(gray)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==1 & group_female==0, lcolor(black)), ///
legend (off) ///
xscale(range(1 4)) xsize(9) ysize(7) ///
xlabel(1 "4th" 2 "3rd" 3 "2nd" 4 "1st", noticks labsize(large)) ///
xtitle("Relative performance on first task", size(6)) ///
ytitle("Updating (0=min, 1=max)", size(6)) ///
ylabel(0.1(0.1)0.5, labsize(large)) ///
graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white))
graph export "figure3b.pdf", replace
graph export "figure3b.tif", replace

restore

******3c: election rank (ties averaged)

preserve

gen ci_lb=.
gen ci_ub=.

gen se_lb=.
gen se_ub=.

foreach y in 1 2 3 4 {

*Women in male dominated teams
ci means election_rank_ties_averaged_rev if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==1 & group_female==0 & rank_perf_1_reversed==`y'

*Women in female dominated teams 
ci means election_rank_ties_averaged_rev if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==1 & group_female==1 & rank_perf_1_reversed==`y'

*Men in male dominated teams 
ci means election_rank_ties_averaged_rev if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==0 & group_female==0 & rank_perf_1_reversed==`y'

*Men in female dominated teams 
ci means election_rank_ties_averaged_rev if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
}

sort female group_female

collapse (mean) election_rank_ties_averaged_rev ci_lb ci_ub se_lb se_ub, by(female rank_perf_1_reversed group_female)

sort rank_perf_1_reversed

*Graph (all)
twoway (scatter election_rank_ties_averaged_rev rank_perf_1_reversed if female==0 & group_female==1, connect(l) lcolor(gray) mcolor(gray) lpattern(dash) msymbol(d)) ///
(scatter election_rank_ties_averaged_rev rank_perf_1_reversed if female==0 & group_female==0, connect(l) lcolor(black) mcolor(black) lpattern(dash) msymbol(d)) ///
(scatter election_rank_ties_averaged_rev rank_perf_1_reversed if female==1 & group_female==1, connect(l) lcolor(gray) mcolor(gray)) ///
(scatter election_rank_ties_averaged_rev rank_perf_1_reversed if female==1 & group_female==0, connect(l) lcolor(black) mcolor(black)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==0 & group_female==1, lcolor(gray)) /// 
(rcap se_ub se_lb rank_perf_1_reversed if female==0 & group_female==0, lcolor(black)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==1 & group_female==1, lcolor(gray)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==1 & group_female==0, lcolor(black)), ///
legend(off) ///
xscale(range(1 4)) xsize(9) ysize(7) ///
xlabel(1 "4th" 2 "3rd" 3 "2nd" 4 "1st", noticks labsize(large)) ///
xtitle("Relative performance on first task", size(6)) ///
ytitle("Rank in election", size(6)) ///
ylabel(1 "4th" 2 "3rd" 3 "2nd" 4 "1st", labsize(large)) ///
graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white))
graph export "figure3c.pdf", replace
graph export "figure3c.tif", replace

restore

******3d: guess election rank
preserve

gen ci_lb=.
gen ci_ub=.

gen se_lb=.
gen se_ub=.

foreach y in 1 2 3 4 {

*Women in male dominated teams
ci means election_guess_rank_reversed if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==1 & group_female==0 & rank_perf_1_reversed==`y'

*Women in female dominated teams 
ci means election_guess_rank_reversed if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==1 & group_female==1 & rank_perf_1_reversed==`y'

*Men in male dominated teams 
ci means election_guess_rank_reversed if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==0 & group_female==0 & rank_perf_1_reversed==`y'

*Men in female dominated teams 
ci means election_guess_rank_reversed if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
}

sort female group_female

collapse (mean) election_guess_rank_reversed ci_lb ci_ub se_lb se_ub, by(female rank_perf_1_reversed group_female)

sort rank_perf_1_reversed

*Graph (all)
twoway (scatter election_guess_rank_reversed rank_perf_1_reversed if female==0 & group_female==1, connect(l) lcolor(gray) mcolor(gray) lpattern(dash) msymbol(d)) ///
(scatter election_guess_rank_reversed rank_perf_1_reversed if female==0 & group_female==0, connect(l) lcolor(black) mcolor(black) lpattern(dash) msymbol(d)) ///
(scatter election_guess_rank_reversed rank_perf_1_reversed if female==1 & group_female==1, connect(l) lcolor(gray) mcolor(gray)) ///
(scatter election_guess_rank_reversed rank_perf_1_reversed if female==1 & group_female==0, connect(l) lcolor(black) mcolor(black)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==0 & group_female==1, lcolor(gray)) /// 
(rcap se_ub se_lb rank_perf_1_reversed if female==0 & group_female==0, lcolor(black)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==1 & group_female==1, lcolor(gray)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==1 & group_female==0, lcolor(black)), ///
legend(off) ///
xscale(range(1 4)) xsize(9) ysize(7) ///
xlabel(1 "4th" 2 "3rd" 3 "2nd" 4 "1st", noticks labsize(large)) ///
xtitle("Relative performance on first task", size(6)) ///
ytitle("Guess of election rank", size(6)) ///
ylabel(1 "4th" 2 "3rd" 3 "2nd" 4 "1st", labsize(large)) ///
graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white))
graph export "figure3d.pdf", replace
graph export "figure3d.tif", replace

restore

******3e: influence
preserve

gen ci_lb=.
gen ci_ub=.

gen se_lb=.
gen se_ub=.

foreach y in 1 2 3 4 {

*Women in male dominated teams
ci means influence if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==1 & group_female==0 & rank_perf_1_reversed==`y'

*Women in female dominated teams 
ci means influence if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==1 & group_female==1 & rank_perf_1_reversed==`y'

*Men in male dominated teams 
ci means influence if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==0 & group_female==0 & rank_perf_1_reversed==`y'

*Men in female dominated teams 
ci means influence if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
}

sort female group_female

collapse (mean) influence ci_lb ci_ub se_lb se_ub, by(female rank_perf_1_reversed group_female)

sort rank_perf_1_reversed

*Graph (all)
twoway (scatter influence rank_perf_1_reversed if female==0 & group_female==1, connect(l) lcolor(gray) mcolor(gray) lpattern(dash) msymbol(d)) ///
(scatter influence rank_perf_1_reversed if female==0 & group_female==0, connect(l) lcolor(black) mcolor(black) lpattern(dash) msymbol(d)) ///
(scatter influence rank_perf_1_reversed if female==1 & group_female==1, connect(l) lcolor(gray) mcolor(gray)) ///
(scatter influence rank_perf_1_reversed if female==1 & group_female==0, connect(l) lcolor(black) mcolor(black)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==0 & group_female==1, lcolor(gray)) /// 
(rcap se_ub se_lb rank_perf_1_reversed if female==0 & group_female==0, lcolor(black)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==1 & group_female==1, lcolor(gray)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==1 & group_female==0, lcolor(black)), ///
legend(off) ///
xscale(range(1 4)) xsize(9) ysize(7) ///
xlabel(1 "4th" 2 "3rd" 3 "2nd" 4 "1st", noticks labsize(large)) ///
xtitle("Relative performance on first task", size(6)) ///
ytitle("Influence (0=min, 1=max)", size(6)) ///
ylabel(0.6(0.05)0.85, labsize(large)) ///
graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white))
graph export "figure3e.pdf", replace
graph export "figure3e.tif", replace

restore

******3f: performance stage 8 

preserve

gen ci_lb=.
gen ci_ub=.

gen se_lb=.
gen se_ub=.

foreach y in 1 2 3 4 {

*Women in male dominated teams
ci means Performance_8 if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==1 & group_female==0 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==1 & group_female==0 & rank_perf_1_reversed==`y'

*Women in female dominated teams 
ci means Performance_8 if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==1 & group_female==1 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==1 & group_female==1 & rank_perf_1_reversed==`y'

*Men in male dominated teams 
ci means Performance_8 if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==0 & group_female==0 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==0 & group_female==0 & rank_perf_1_reversed==`y'

*Men in female dominated teams 
ci means Performance_8 if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_lb=r(lb) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace ci_ub=r(ub) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace se_lb=r(mean)-r(se) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
replace se_ub=r(mean)+r(se) if female==0 & group_female==1 & rank_perf_1_reversed==`y'
}

sort female group_female

collapse (mean) Performance_8 ci_lb ci_ub se_lb se_ub, by(female rank_perf_1_reversed group_female)

sort rank_perf_1_reversed

*Graph (all)
twoway (scatter Performance_8 rank_perf_1_reversed if female==0 & group_female==1, connect(l) lcolor(gray) mcolor(gray) lpattern(dash) msymbol(d)) ///
(scatter Performance_8 rank_perf_1_reversed if female==0 & group_female==0, connect(l) lcolor(black) mcolor(black) lpattern(dash) msymbol(d)) ///
(scatter Performance_8 rank_perf_1_reversed if female==1 & group_female==1, connect(l) lcolor(gray) mcolor(gray)) ///
(scatter Performance_8 rank_perf_1_reversed if female==1 & group_female==0, connect(l) lcolor(black) mcolor(black)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==0 & group_female==1, lcolor(gray)) /// 
(rcap se_ub se_lb rank_perf_1_reversed if female==0 & group_female==0, lcolor(black)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==1 & group_female==1, lcolor(gray)) ///
(rcap se_ub se_lb rank_perf_1_reversed if female==1 & group_female==0, lcolor(black)), ///
legend (off) ///
xscale(range(1 4)) xsize(9) ysize(7) ///
xlabel(1 "4th" 2 "3rd" 3 "2nd" 4 "1st", noticks labsize(large)) ///
xtitle("Relative performance on first task", size(6)) ///
ytitle("Performance 2nd task (50=best)", size(6)) ///
ylabel(20(2)30, labsize(large)) ///
graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white))
graph export "figure3f.pdf", replace
graph export "figure3f.tif", replace

restore

***********************************************************************
************************FIGURE 4a: OVERALL GENDER GAP*****************
***********************************************************************
use "data.dta", clear
set more off

***CREATE MATRIX

matrix M=J(8,3,.)
matrix coln M = change row_nr p_value
matrix rown M = guess_rank_1 relative_updating election_rank election_guess_rank influence PenaltyPoints_8 mean_othergr_iatresultmain all

***BASELINE COEFF

reg leadasp male rank_perf_1, cluster(group_id)
scalar baseline=_b[male]

***CHANGES IN OVERALL GENDER GAP WHEN ADDING CONTROL VARIABLES

*guess of own performance
reg leadasp male rank_perf_1 guess_rank_1, cluster(group_id)
matrix M[8,1]=-[1-_b[male]/baseline]*100
matrix M[8,2]=8

**relative updating
reg leadasp male rank_perf_1 relative_updating , cluster(group_id)
matrix M[7,1]=-[1-_b[male]/baseline]*100
matrix M[7,2]=7

*rank in election
reg leadasp male rank_perf_1 election_rank_ties_averaged_rev , cluster(group_id)
matrix M[6,1]=-[1-_b[male]/baseline]*100
matrix M[6,2]=6

*guess of rank in election
reg leadasp male rank_perf_1 election_guess_rank , cluster(group_id)
matrix M[5,1]=-[1-_b[male]/baseline]*100
matrix M[5,2]=5

*influence
reg leadasp male rank_perf_1 influence, cluster(group_id)
matrix M[4,1]=-[1-_b[male]/baseline]*100
matrix M[4,2]=4

*penalty points in stage 8
reg leadasp male rank_perf_1 PenaltyPoints_8, cluster(group_id)
matrix M[3,1]=-[1-_b[male]/baseline]*100
matrix M[3,2]=3

*IAT of other group members
reg leadasp male rank_perf_1 mean_othergr_iatresultmain, cluster(group_id)
matrix M[2,1]=-[1-_b[male]/baseline]*100
matrix M[2,2]=2

*all
reg leadasp male rank_perf_1 guess_rank_1 relative_updating election_guess_rank PenaltyPoints_8 election_rank_ties_averaged_rev influence mean_othergr_iatresultmain, cluster(group_id)
matrix M[1,1]=-[1-_b[male]/baseline]*100
matrix M[1,2]=1

***SUEST FOR P-VALUES

*guess of own performance
reg leadasp male rank_perf_1
est store V1
reg leadasp male rank_perf_1 guess_rank_1
est sto V2
suest V1 V2, cluster(group_id)
test [V1_mean=V2_mean]:male
matrix M[8,3]=r(p)

**relative updating
reg leadasp male rank_perf_1
est store V1
reg leadasp male rank_perf_1 relative_updating
est sto V2
suest V1 V2, cluster(group_id)
test [V1_mean=V2_mean]:male
matrix M[7,3]=r(p)

*rank in election
reg leadasp male rank_perf_1
est store V1
reg leadasp male rank_perf_1 election_rank_ties_averaged_rev
est sto V2
suest V1 V2, cluster(group_id)
test [V1_mean=V2_mean]:male
matrix M[6,3]=r(p)

*guess of rank in election
reg leadasp male rank_perf_1
est store V1
reg leadasp male rank_perf_1 election_guess_rank
est sto V2
suest V1 V2, cluster(group_id)
test [V1_mean=V2_mean]:male
matrix M[5,3]=r(p)

*influence
reg leadasp male rank_perf_1
est store V1
reg leadasp male rank_perf_1 influence
est sto V2
suest V1 V2, cluster(group_id)
test [V1_mean=V2_mean]:male
matrix M[4,3]=r(p)

*penalty points in stage 8
reg leadasp male rank_perf_1
est store V1
reg leadasp male rank_perf_1 PenaltyPoints_8
est sto V2
suest V1 V2, cluster(group_id)
test [V1_mean=V2_mean]:male
matrix M[3,3]=r(p)

*IAT of other group members
reg leadasp male rank_perf_1
est store V1
reg leadasp male rank_perf_1 mean_othergr_iatresultmain
est sto V2
suest V1 V2, cluster(group_id)
test [V1_mean=V2_mean]:male
matrix M[2,3]=r(p)

*all
reg leadasp male rank_perf_1
est store V1
reg leadasp male rank_perf_1 guess_rank_1 relative_updating election_guess_rank PenaltyPoints_8 election_rank_ties_averaged_rev influence mean_othergr_iatresultmain
est sto V2
suest V1 V2, cluster(group_id)
test [V1_mean=V2_mean]:male
matrix M[1,3]=r(p)

***SAVE MATRIX AS VARIABLES

clear
svmat M, names(col)

***FIGURE

gen x = change-23
gen y = row_nr
gen y1 = row_nr+0.12
gen y2 = row_nr-0.12


gen change_text = string(change, "%4.2f") + "%"

gen p_value_text = ""
replace p_value_text="***" if row_nr==1 | row_nr==4 | row_nr==5 | row_nr==6 | row_nr==7 | row_nr==8
replace p_value_text="" if row_nr==2
replace p_value_text="" if row_nr==3

gen text = ""
replace text = change_text + " " + p_value_text

twoway ///
bar change row_nr if row_nr!=2 & row_nr!=3, horizontal barw(0.8) bcolor(gs4) xline(0, lpattern(dash)) ///
|| bar change row_nr if row_nr==2 | row_nr==3, horizontal barw(0.8) bcolor(gs11) ///
xtitle("Change in coefficient of 'Male' (%)", size(5)) ///
graphregion(color(white)) xsize(20) ysize(10) ///
ymlabel(8 "Guess of relative perf. on 1st task" 7 "Updating propensity" 6 "Rank in election" 5 "Guess of election rank" 4 "Influence on team" 3 "Performance on 2nd task" 2 "IAT scores of team members" 1 "All controls", noticks labsize(4) labgap(*1) angle(0)) ///
ytitle("CONTROL VARIABLES", size(5)) ylabel(, nolabel noticks) yscale(alt) ///
xlabel(10 "+10" 0 "0" -10 "-10" -20 "-20" -30 "-30" -40 "-40" -50 "-50" -60 "-60" -70 "-70" -80 "-80" -90 "-90" -100 "-100" -108 " ", nogrid labsize(5) angle(45)) ///
|| scatter y x , ms(none) mlab(text) mlabsize(4) mlabcolor(black) legend(off) ylab(,nogrid)
graph export "figure4a.pdf", replace


***********************************************************************
************************FIGURE 4b: TREATMENT EFFECT ON WOMEN***********
***********************************************************************
use "data.dta", clear
set more off

clear matrix
capture log close
xtset, clear

***CREATE MATRIX

matrix M=J(8,3,.)
matrix coln M = change row_nr p_value
matrix rown M = guess_rank_1 relative_updating election_rank election_guess_rank influence PenaltyPoints_8 mean_othergr_iatresultmain all


***BASELINE COEFF

reg leadasp male group_male male_X_group_male rank_perf_1 male_X_rank_perf_1, cluster(group_id)
scalar baseline=_b[group_male]

***CHANGES IN OVERALL GENDER GAP WHEN ADDING CONTROL VARIABLES

*guess of own performance
reg leadasp male group_male male_X_group_male rank_perf_1 male_X_rank_perf_1 guess_rank_1 male_X_guess_rank_1, cluster(group_id)
matrix M[8,1]=-[1-_b[group_male]/baseline]*100
matrix M[8,2]=8

**relative updating
reg leadasp male group_male male_X_group_male rank_perf_1 male_X_rank_perf_1 relative_updating male_X_relative_updating, cluster(group_id)
matrix M[7,1]=-[1-_b[group_male]/baseline]*100
matrix M[7,2]=7

*rank in election
reg leadasp male group_male male_X_group_male rank_perf_1 male_X_rank_perf_1 election_rank_ties_averaged_rev male_X_elec_rank_ties_av_rev , cluster(group_id)
matrix M[6,1]=-[1-_b[group_male]/baseline]*100
matrix M[6,2]=6

*guess of rank in election
reg leadasp male group_male male_X_group_male rank_perf_1 male_X_rank_perf_1 election_guess_rank male_X_election_guess_rank , cluster(group_id)
matrix M[5,1]=-[1-_b[group_male]/baseline]*100
matrix M[5,2]=5

*influence
reg leadasp male group_male male_X_group_male rank_perf_1 male_X_rank_perf_1 influence male_X_influence , cluster(group_id)
matrix M[4,1]=-[1-_b[group_male]/baseline]*100
matrix M[4,2]=4

*penalty points in stage 8
reg leadasp male group_male male_X_group_male rank_perf_1 male_X_rank_perf_1 PenaltyPoints_8 male_X_PenaltyPoints_8 , cluster(group_id)
matrix M[3,1]=-[1-_b[group_male]/baseline]*100
matrix M[3,2]=3

*IAT of other group members
reg leadasp male group_male male_X_group_male rank_perf_1 male_X_rank_perf_1 mean_othergr_iatresultmain male_X_othergr_iatresmain , cluster(group_id)
matrix M[2,1]=-[1-_b[group_male]/baseline]*100
matrix M[2,2]=2

*all
reg leadasp male group_male male_X_group_male rank_perf_1 male_X_rank_perf_1 guess_rank_1 relative_updating election_guess_rank PenaltyPoints_8 election_rank_ties_averaged_rev influence mean_othergr_iatresultmain male_X_guess_rank_1 male_X_relative_updating male_X_elec_rank_ties_av_rev male_X_election_guess_rank male_X_influence male_X_PenaltyPoints_8 male_X_othergr_iatresmain, cluster(group_id)
matrix M[1,1]=-[1-_b[group_male]/baseline]*100
matrix M[1,2]=1

***SUEST FOR P-VALUES

*guess of own performance
reg leadasp group_male rank_perf_1 if female==1
est store V1
reg leadasp group_male rank_perf_1 guess_rank_1 if female==1
est sto V2
suest V1 V2, cluster(group_id)
test [V1_mean=V2_mean]:group_male
matrix M[8,3]=r(p)

**relative updating
reg leadasp group_male rank_perf_1 if female==1
est store V1
reg leadasp group_male rank_perf_1 relative_updating if female==1
est sto V2
suest V1 V2, cluster(group_id)
test [V1_mean=V2_mean]:group_male
matrix M[7,3]=r(p)

*rank in election
reg leadasp group_male rank_perf_1 if female==1
est store V1
reg leadasp group_male rank_perf_1 election_rank_ties_averaged_rev if female==1
est sto V2
suest V1 V2, cluster(group_id)
test [V1_mean=V2_mean]:group_male
matrix M[6,3]=r(p)

*guess of rank in election
reg leadasp group_male rank_perf_1 if female==1
est store V1
reg leadasp group_male rank_perf_1 election_guess_rank if female==1
est sto V2
suest V1 V2, cluster(group_id)
test [V1_mean=V2_mean]:group_male
matrix M[5,3]=r(p)

*influence
reg leadasp group_male rank_perf_1 if female==1
est store V1
reg leadasp group_male rank_perf_1 influence if female==1
est sto V2
suest V1 V2, cluster(group_id)
test [V1_mean=V2_mean]:group_male
matrix M[4,3]=r(p)


*penalty points in stage 8 
reg leadasp group_male rank_perf_1 if female==1
est store V1
reg leadasp group_male rank_perf_1 PenaltyPoints_8 if female==1
est sto V2
suest V1 V2, cluster(group_id)
test [V1_mean=V2_mean]:group_male
matrix M[3,3]=r(p)

*IAT of other group members
reg leadasp group_male rank_perf_1 if female==1
est store V1
reg leadasp group_male rank_perf_1 mean_othergr_iatresultmain if female==1
est sto V2
suest V1 V2, cluster(group_id)
test [V1_mean=V2_mean]:group_male
matrix M[2,3]=r(p)

*all
reg leadasp group_male rank_perf_1 if female==1
est store V1
reg leadasp group_male rank_perf_1 guess_rank_1 relative_updating election_guess_rank PenaltyPoints_8 election_rank_ties_averaged_rev influence mean_othergr_iatresultmain if female==1
est sto V2
suest V1 V2, cluster(group_id)
test [V1_mean=V2_mean]:group_male
matrix M[1,3]=r(p)

***SAVE MATRIX AS VARIABLES

clear
svmat M, names(col)

***FIGURE

gen x = change - 23
replace x = -23 if change>0

gen y = row_nr
gen y1 = row_nr+0.12
gen y2 = row_nr-0.12
gen change_text = string(change, "%4.2f") + "%"
replace change_text = "+" + string(change, "%4.2f") + "%" if change>0

gen p_value_text = ""
replace p_value_text="*" if row_nr==1
replace p_value_text="" if row_nr==2
replace p_value_text="" if row_nr==3
replace p_value_text="*" if row_nr==4
replace p_value_text="*" if row_nr==5
replace p_value_text="" if row_nr==6
replace p_value_text="*  " if row_nr==7
replace p_value_text="***" if row_nr==8

gen text = ""
replace text = change_text + " " + p_value_text

twoway ///
bar change row_nr if row_nr!=2 & row_nr!=3 & row_nr!=6, horizontal barw(0.8) bcolor(gs4) xline(0, lpattern(dash)) ///
|| bar change row_nr if row_nr==2 | row_nr==3 | row_nr==6, horizontal barw(0.8) bcolor(gs11) ///
xtitle("Change in coefficient of 'Male-majority team' (%)", size(5)) ///
graphregion(color(white)) xsize(20) ysize(10) ///
ymlabel(8 "Guess of relative perf. on 1st task" 7 "Updating propensity" 6 "Rank in election" 5 "Guess of election rank" 4 "Influence on team" 3 "Performance on 2nd task" 2 "IAT scores of team members" 1 "All controls", noticks labsize(4) labgap(*1) angle(0)) ///
ytitle("CONTROL VARIABLES", size(5)) ylabel(, nolabel noticks) yscale(alt) ///
xlabel(10 "+10" 0 "0" -10 "-10" -20 "-20" -30 "-30" -40 "-40" -50 "-50" -60 "-60" -70 "-70" -80 "-80" -90 "-90" -100 "-100" -108 " ", nogrid labsize(5) angle(45)) ///
|| scatter y x , ms(none) mlab(text) mlabsize(4) mlabcolor(black) legend(off) ylab(,nogrid)
graph export "figure4b.pdf", replace


***********************************************************************
************************FIGURE 5a: BECOMING CANDIDATE******************
***********************************************************************
use "data.dta", clear
set more off

preserve

gen ci_lb=.
gen ci_ub=.
gen se_lb=.
gen se_ub=.

*Women in male dominated teams 
ci means candidate if female==1 & group_female==0
replace ci_lb=r(lb) if female==1 & group_female==0
replace ci_ub=r(ub) if female==1 & group_female==0
replace se_lb=r(mean)-r(se) if female==1 & group_female==0
replace se_ub=r(mean)+r(se) if female==1 & group_female==0

*Women in female dominated teams 
ci means candidate if female==1 & group_female==1
replace ci_lb=r(lb) if female==1 & group_female==1
replace ci_ub=r(ub) if female==1 & group_female==1
replace se_lb=r(mean)-r(se) if female==1 & group_female==1
replace se_ub=r(mean)+r(se) if female==1 & group_female==1

*Men in male dominated teams 
ci means candidate if female==0 & group_female==0
replace ci_lb=r(lb) if female==0 & group_female==0
replace ci_ub=r(ub) if female==0 & group_female==0
replace se_lb=r(mean)-r(se) if female==0 & group_female==0
replace se_ub=r(mean)+r(se) if female==0 & group_female==0

*Men in female dominated teams 
ci means candidate if female==0 & group_female==1
replace ci_lb=r(lb) if female==0 & group_female==1
replace ci_ub=r(ub) if female==0 & group_female==1
replace se_lb=r(mean)-r(se) if female==0 & group_female==1
replace se_ub=r(mean)+r(se) if female==0 & group_female==1

sort female group_female

collapse (mean) candidate ci_lb ci_ub se_lb se_ub, by(female group_female)

*Help Variables
generate x_axis=0.1 if female==1 & group_female==1
replace x_axis=0.3 if female==1 & group_female==0

replace x_axis=0.7 if female==0 & group_female==1
replace x_axis=0.9 if female==0 & group_female==0

sort x_axis
label var x_axis " "

gen half=0.5

gen zero_one=0
replace zero=1 if female==1

*Bar Chart
twoway (bar candidate x_axis if female==1 & group_female==1, barw(0.15) bcolor(gs10)) ///
(bar candidate x_axis if female==1 & group_female==0, barw(0.15) bcolor(gs1)) ///
(bar candidate x_axis if female==0 & group_female==1, barw(0.15) bcolor(gs10)) ///
(bar candidate x_axis if female==0 & group_female==0, barw(0.15) bcolor(gs1)) ///
(rcap se_ub se_lb x_axis, lcolor(gs1.5)) ///
(line half zero_one, msize(*19) lcolor(black) lpattern(dash)), ///
legend(row(1) order(1 "Female-majority team" 2 "Male-majority team") size(medlarge) symxsize(10) keygap(0.8) position(6)) ///
b2title("- - - - - average probability of becoming candidate", box fcolor(none) size(medlarge)) ///
xscale(range(0 1)) ///
xlabel(0.2 "Women" 0.8 "Men", noticks labsize(large)) ///
ytitle("Prob. of becoming candidate", size(5)) ///
ylabel(0(0.1)0.8, labsize(medlarge)) ///
graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white))
graph export "figure5a.pdf", replace

restore

***********************************************************************
************************FIGURE 5B: BECOMING LEADER*********************
***********************************************************************
use "data.dta", clear
set more off

preserve

gen ci_lb=.
gen ci_ub=.
gen se_lb=.
gen se_ub=.

*Women in male dominated teams 
ci means leader if female==1 & group_female==0
replace ci_lb=r(lb) if female==1 & group_female==0
replace ci_ub=r(ub) if female==1 & group_female==0
replace se_lb=r(mean)-r(se) if female==1 & group_female==0
replace se_ub=r(mean)+r(se) if female==1 & group_female==0

*Women in female dominated teams 
ci means leader  if female==1 & group_female==1
replace ci_lb=r(lb) if female==1 & group_female==1
replace ci_ub=r(ub) if female==1 & group_female==1
replace se_lb=r(mean)-r(se) if female==1 & group_female==1
replace se_ub=r(mean)+r(se) if female==1 & group_female==1

*Men in male dominated teams 
ci means leader  if female==0 & group_female==0
replace ci_lb=r(lb) if female==0 & group_female==0
replace ci_ub=r(ub) if female==0 & group_female==0
replace se_lb=r(mean)-r(se) if female==0 & group_female==0
replace se_ub=r(mean)+r(se) if female==0 & group_female==0

*Men in female dominated teams 
ci means leader  if female==0 & group_female==1
replace ci_lb=r(lb) if female==0 & group_female==1
replace ci_ub=r(ub) if female==0 & group_female==1
replace se_lb=r(mean)-r(se) if female==0 & group_female==1
replace se_ub=r(mean)+r(se) if female==0 & group_female==1

sort female group_female

collapse (mean) leader  ci_lb ci_ub se_lb se_ub, by(female group_female)

*Help Variables
generate x_axis=0.1 if female==1 & group_female==1
replace x_axis=0.3 if female==1 & group_female==0

replace x_axis=0.7 if female==0 & group_female==1
replace x_axis=0.9 if female==0 & group_female==0

sort x_axis
label var x_axis " "

gen one_fourth=0.25
gen zero_one=0
replace zero=1 if female==1

*Bar Chart
twoway (bar leader  x_axis if female==1 & group_female==1, barw(0.15) bcolor(gs10)) ///
(bar leader  x_axis if female==1 & group_female==0, barw(0.15) bcolor(gs1)) ///
(bar leader  x_axis if female==0 & group_female==1, barw(0.15) bcolor(gs10)) ///
(bar leader  x_axis if female==0 & group_female==0, barw(0.15) bcolor(gs1)) ///
(rcap se_ub se_lb x_axis, lcolor(gs1.5)) /// 
(line one_fourth zero_one, msize(*19) lcolor(black) lpattern(dash)), ///
legend(row(1) order(1 "Female-majority team" 2 "Male-majority team") size(medlarge) symxsize(10) keygap(0.8) position(6)) ///b2title("- - - - - average probability of becoming leader", box fcolor(none) size(medsmall)) ///
b2title("- - - - - average probability of becoming leader", box fcolor(none) size(medlarge)) ///
xscale(range(0 1)) ///
xlabel(0.2 "Women" 0.8 "Men", noticks labsize(large)) ///
ytitle("Prob. of becoming leader", size(5)) ///
ylabel(0(0.1)0.6, labsize(medlarge)) ///
graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white))
graph export "figure5b.pdf", replace
restore

******************************
**** TABLE 1 *****************
******************************

use "data.dta", clear
set more off

reg leadasp male, cluster(group_id)

outreg using "table1.rtf", starlevels (5 1 0.1) starloc(1) statfont(fs12) se summstat(N) summtitle("N") varlabels replace ///
ctitles("", "(1)") ///
addrows(" ", " " \ "\underline{'Male team+ 'Male X Male team':}", " " \ "Effect size:", " " \ "F statistic:", " " \ "p-value:", " ")  

reg leadasp male rank_perf_1, cluster(group_id)

outreg, starlevels (5 1 0.1) starloc(1) statfont(fs12) se summstat(N) summtitle("N") varlabels merge ///
ctitles("", "(2)") ///
addrows(" ", " " \ "\underline{'Male team+ 'Male X Male team':}", " " \ "Effect size:", " " \ "F statistic:", " " \ "p-value:", " ")  

reg leadasp male group_male male_X_group_male, cluster(group_id)
lincom group_male+male_X_group_male
local s : display %4.3f `r(estimate)'
test group_male+male_X_group_male=0
local p : display %4.3f `r(p)'
local F : display %4.3f `r(F)'

outreg, starlevels (5 1 0.1) starloc(1) statfont(fs12) se summstat(N) summtitle("N") varlabels merge ///
ctitles("", "(3)") ///
addrows(" ", " " \ "\underline{'Male group' + 'Male X Female group':}", " " \ "Effect size:", "`s'" \ "F statistic:", "`F'" \ "p-value:", "`p'")

reg leadasp male group_male male_X_group_male rank_perf_1 male_X_rank_perf_1, cluster(group_id)
lincom group_male+male_X_group_male
local s : display %4.3f `r(estimate)'
test group_male+male_X_group_male=0
local p : display %4.3f `r(p)'
local F : display %4.3f `r(F)'

outreg using "table1.rtf", starlevels (5 1 0.1) starloc(1) statfont(fs12) se summstat(N) summtitle("N") varlabels merge ///
ctitles("", "(4)") ///
addrows(" ", " " \ "\underline{'Male team+ 'Male X Male team':}", " " \ "Effect size:", "`s'" \ "F statistic:", "`F'" \ "p-value:", "`p'")  ///
note("Note: Standard errors are clustered on the team level. The three final rows present results from an F-test, testing the treatment effect for men.") ///
title ("Dependent variable: Leadership aspirations")

******************************
**** TABLE 2 *****************
******************************

*************a. OVERALL GENDER GAP 
use "data.dta", clear
set more off

*guess of rank in first task

reg guess_rank_1_reversed male rank_perf_1, cluster(group_id)

outreg using "table2a.rtf", starlevels (5 1 0.1) starloc(1) statfont(fs12) se summstat(N) summtitle("N") varlabels replace ///
ctitles(" " , "Guess rank" \ " " , "stage 1")

*relative updating

reg relative_updating male rank_perf_1, cluster(group_id)

outreg, varlabels starlevels (5 1 0.1) starloc(1) statfont(fs12) se summdec(3 0)summstat(N) summtitle("N") merge ///
ctitles(" " , "Updating" \ " " , "stage 3") 

*rank in election (ties averaged)

reg election_rank_ties_averaged_rev male rank_perf_1, cluster(group_id)

outreg, varlabels starlevels (5 1 0.1) starloc(1) statfont(fs12) se summdec(3 0)summstat(N) summtitle("N")  merge ///
ctitles(" " , "Rank election" \ " " , "(1=worst, 4=best)") 

*guess of rank in election

reg election_guess_rank_reversed male rank_perf_1, cluster(group_id)

outreg, varlabels starlevels (5 1 0.1) starloc(1) statfont(fs12) se summdec(3 0)summstat(N) summtitle("N") merge ///
ctitles(" " , "Guess rank elect." \ " " , "(1=worst, 4=best)") 

*influence in group discussion

reg influence male rank_perf_1, cluster(group_id)

outreg, varlabels starlevels (5 1 0.1) starloc(1) statfont(fs12) se summdec(3 0)summstat(N) summtitle("N")  merge ///
ctitles(" " , "Influence" \ " " , " ") 

*Performance stage 8

reg Performance_8 male rank_perf_1, cluster(group_id)

outreg, varlabels starlevels (5 1 0.1) starloc(1) statfont(fs12) se summdec(3 0)summstat(N) summtitle("N") merge ///
ctitles(" " , "Performance" \ " " , "stage 8") 

*IAT score of other team members

reg mean_othergr_iatresultmain male rank_perf_1, cluster(group_id)

outreg using "table2a.rtf", starlevels (5 1 0.1) starloc(1) statfont(fs12) se summstat(N) summtitle("N") varlabels landscape merge ///
ctitles(" " , "IAT" \ " " , "other team members") ///
note("Note: Standard errors are clustered on the team level. 'Guess rank stage 1' denotes the participant's guess (from stage 3) of their within-team ranking in terms of stage one performance, on a scale where 1=best in the team and 4=worst in the team.'Updating stage 3' indicates how much the participant updated their answers from stage 1 in stage 3, relative to the rest of the team (0=the participant did not update, 1=the participant was the only one in the team who updated). 'Guess rank election' denotes the participant's guess of their ranking in the election based on all votes, where 1=highest in group and 4=lowest in group. 'Penalty points stage 8' indicates the participant's individual performance in the desert survival task in stage 8, where 0=best possible and 50=worst possible. 'Average vote election' denotes the average vote received by the participant in the leadership election, where 3=everyone ranked the participant highest and 1=everyone ranked the participant lowest. 'Influence' denotes how close the team answer in stage 2 was to an individual's solution in stage 1 relative to the team.") ///
title ("Dependent variable: 'Mechanism variables'")


*************b. TREATMENT EFFECT
use "data.dta", clear
set more off

*guess of rank in first task

reg guess_rank_1_reversed male group_male male_X_group_male rank_perf_1 male_X_rank_perf_1, cluster(group_id)
lincom group_male+male_X_group_male
local s : display %4.3f `r(estimate)'
test group_male+male_X_group_male=0
local p : display %4.3f `r(p)'
local F : display %4.3f `r(F)'

outreg using "table2b.rtf", starlevels (5 1 0.1) starloc(1) statfont(fs12) se summstat(N) summtitle("N") varlabels replace ///
ctitles(" " , "Guess rank" \ " " , "stage 1") ///
addrows(" ", " " \ "\underline{'Male team+ 'Male X Male team':}", " " \ "Effect size:", "`s'" \ "F statistic:", "`F'" \ "p-value:", "`p'")

*relative updating

reg relative_updating male group_male male_X_group_male rank_perf_1 male_X_rank_perf_1, cluster(group_id)
lincom group_male+male_X_group_male
local s : display %4.3f `r(estimate)'
test group_male+male_X_group_male=0
local p : display %4.3f `r(p)'
local F : display %4.3f `r(F)'

outreg, varlabels starlevels (5 1 0.1) starloc(1) statfont(fs12) se summdec(3 0)summstat(N) summtitle("N") merge ///
ctitles(" " , "Updating" \ " " , "stage 3") ///
addrows(" ", " " \ "\underline{'Male team+ 'Male X Male team':}", " " \ "Effect size:", "`s'" \ "F statistic:", "`F'" \ "p-value:", "`p'")

*rank in election (ties averaged)

reg election_rank_ties_averaged_rev male group_male male_X_group_male rank_perf_1 male_X_rank_perf_1, cluster(group_id)
lincom group_male+male_X_group_male
local s : display %4.3f `r(estimate)'
test group_male+male_X_group_male=0
local p : display %4.3f `r(p)'
local F : display %4.3f `r(F)'

outreg, varlabels starlevels (5 1 0.1) starloc(1) statfont(fs12) se summdec(3 0)summstat(N) summtitle("N") merge ///
ctitles(" " , "Rank election" \ " " , " ") ///
addrows(" ", " " \ "\underline{'Male team+ 'Male X Male team':}", " " \ "Effect size:", "`s'" \ "F statistic:", "`F'" \ "p-value:", "`p'")


*guess of rank in election

reg election_guess_rank_reversed male group_male male_X_group_male rank_perf_1 male_X_rank_perf_1, cluster(group_id)
lincom group_male+male_X_group_male
local s : display %4.3f `r(estimate)'
test group_male+male_X_group_male=0
local p : display %4.3f `r(p)'
local F : display %4.3f `r(F)'

outreg, varlabels starlevels (5 1 0.1) starloc(1) statfont(fs12) se summdec(3 0)summstat(N) summtitle("N") merge ///
ctitles(" " , "Guess rank" \ " " , "election") ///
addrows(" ", " " \ "\underline{'Male team+ 'Male X Male team':}", " " \ "Effect size:", "`s'" \ "F statistic:", "`F'" \ "p-value:", "`p'")

*influence in group discussion

reg influence male group_male male_X_group_male rank_perf_1 male_X_rank_perf_1, cluster(group_id)
lincom group_male+male_X_group_male
local s : display %4.3f `r(estimate)'
test group_male+male_X_group_male=0
local p : display %4.3f `r(p)'
local F : display %4.3f `r(F)'

outreg, varlabels starlevels (5 1 0.1) starloc(1) statfont(fs12) se summdec(3 0)summstat(N) summtitle("N") merge ///
ctitles(" " , "Influence" \ " " , " ") ///
addrows(" ", " " \ "\underline{'Male team+ 'Male X Male team':}", " " \ "Effect size:", "`s'" \ "F statistic:", "`F'" \ "p-value:", "`p'")


*Performance in stage 8

reg Performance_8 male group_male male_X_group_male rank_perf_1 male_X_rank_perf_1, cluster(group_id)
lincom group_male+male_X_group_male
local s : display %4.3f `r(estimate)'
test group_male+male_X_group_male=0
local p : display %4.3f `r(p)'
local F : display %4.3f `r(F)'

outreg, varlabels starlevels (5 1 0.1) starloc(1) statfont(fs12) se summdec(3 0)summstat(N) summtitle("N") merge ///
ctitles(" " , "Performance" \ " " , "stage 8") ///
addrows(" ", " " \ "\underline{'Male team' + 'Male X Male team':}", " " \ "Effect size:", "`s'" \ "F statistic:", "`F'" \ "p-value:", "`p'")


*IAT score of other team members

reg mean_othergr_iatresultmain male group_male male_X_group_male rank_perf_1 male_X_rank_perf_1, cluster(group_id)
lincom group_male+male_X_group_male
local s : display %4.3f `r(estimate)'
test group_male+male_X_group_male=0
local p : display %4.3f `r(p)'
local F : display %4.3f `r(F)'

outreg using "table2b.rtf", starlevels (5 1 0.1) starloc(1) statfont(fs12) se summstat(N) summtitle("N") varlabels landscape merge ///
ctitles(" " , "IAT score of" \ " " , "team members") ///
addrows(" ", " " \ "\underline{'Male team' + 'Male X Male team':}", " " \ "Effect size:", "`s'" \ "F statistic:", "`F'" \ "p-value:", "`p'") ///
note("Note: Standard errors are clustecranberry on the team level. The three final rows present results from an F-test, testing the treatment effect for men. 'Guess rank stage 1' denotes the participant's guess (from stage 3) of their within-team ranking in terms of stage one performance, on a scale where 1=best in the team and 4=worst in the team.'Updating stage 3' indicates how much the participant updated their answers from stage 1 in stage 3, relative to the rest of the team (0=the participant did not update, 1=the participant was the only one in the team who updated). 'Guess rank election' denotes the participant's guess of their ranking in the election based on all votes, where 1=highest in group and 4=lowest in group. 'Penalty points stage 8' indicates the participant's individual performance in the desert survival task in stage 8, where 0=best possible and 50=worst possible. 'Average vote election' denotes the average vote received by the participant in the leadership election, where 3=everyone ranked the participant highest and 1=everyone ranked the participant lowest. 'Influence' denotes how close the team answer in stage 2 was to an individual's solution in stage 1 relative to the team.") ///
title ("Dependent variable: 'Mechanism variables'")

